package com.ruoyi.web.controller.grape;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.grape.domain.GrapeJob;
import com.ruoyi.grape.service.IGrapeJobService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 农事管理信息Controller
 * 
 * @author ld
 * @date 2024-01-22
 */
@RestController
@RequestMapping("/grape/job")
public class GrapeJobController extends BaseController
{
    @Autowired
    private IGrapeJobService grapeJobService;

    /**
     * 查询农事管理信息列表
     */
    @PreAuthorize("@ss.hasPermi('grape:job:list')")
    @GetMapping("/list")
    public TableDataInfo list(GrapeJob grapeJob)
    {
        startPage();
        List<GrapeJob> list = grapeJobService.selectGrapeJobList(grapeJob);
        return getDataTable(list);
    }

    /**
     * 导出农事管理信息列表
     */
    @PreAuthorize("@ss.hasPermi('grape:job:export')")
    @Log(title = "农事管理信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrapeJob grapeJob)
    {
        List<GrapeJob> list = grapeJobService.selectGrapeJobList(grapeJob);
        ExcelUtil<GrapeJob> util = new ExcelUtil<GrapeJob>(GrapeJob.class);
        util.exportExcel(response, list, "农事管理信息数据");
    }

    /**
     * 获取农事管理信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('grape:job:query')")
    @GetMapping(value = "/{jobId}")
    public AjaxResult getInfo(@PathVariable("jobId") Long jobId)
    {
        return success(grapeJobService.selectGrapeJobByJobId(jobId));
    }

    /**
     * 新增农事管理信息
     */
    @PreAuthorize("@ss.hasPermi('grape:job:add')")
    @Log(title = "农事管理信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrapeJob grapeJob)
    {
        return toAjax(grapeJobService.insertGrapeJob(grapeJob));
    }

    /**
     * 修改农事管理信息
     */
    @PreAuthorize("@ss.hasPermi('grape:job:edit')")
    @Log(title = "农事管理信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrapeJob grapeJob)
    {
        return toAjax(grapeJobService.updateGrapeJob(grapeJob));
    }

    /**
     * 删除农事管理信息
     */
    @PreAuthorize("@ss.hasPermi('grape:job:remove')")
    @Log(title = "农事管理信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{jobIds}")
    public AjaxResult remove(@PathVariable Long[] jobIds)
    {
        return toAjax(grapeJobService.deleteGrapeJobByJobIds(jobIds));
    }
}
